/**
 * OpenAction.java
 * @author: liuex
 * 2007-12-28 ����10:15:16
 *
 * note: 
 */
package org.lex.explorer.file;

import java.awt.event.ActionEvent;
import java.io.File;

public class NewFileAction extends AbstractFileAction {
	public NewFileAction(FileExplorer fileExplorer) {
		super(fileExplorer);
		this.setName("New file");
	}

	public void doInBackground(ActionEvent e) {
		String name = this.input("New file", "Enter file name:", "New Document.txt");
		if (null == name)
			return;
		File dir = this.fileExplorer.getDirectory();
		File file = new File(dir, name);
		if (true == file.exists() && file.isFile()) {
			this.error("File exists", "Can not create file: " + name);
			return;
		} else {
			try {
				file.createNewFile();
				fileExplorer.refresh();
			} catch (Exception ex) {
				this.error("Create file error", ex.getLocalizedMessage());
			}
		}
	}
}
